package com.water_work_form.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.water_work_form.entity.RecordDrugConsume;
import com.water_work_form.entity.RecordProteinNitrogenDetection;
import com.water_work_form.entity.RecordSynchronousComparison;
import com.water_work_form.result.Result;
import com.water_work_form.result.ResultCodeEnum;
import com.water_work_form.result.ResultUtil;
import com.water_work_form.service.RecordProteinNitrogenDetectionService;
import com.water_work_form.util.RandomIdUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 记录——蛋白性氮检测原始记录 前端控制器
 * </p>
 *
 * @author xuke
 * @since 2023-09-14
 */
@Api(tags = {"蛋白质 前端控制器"})
@RestController
@RequestMapping("/record-protein-nitrogen-detection")
public class RecordProteinNitrogenDetectionController {

    @Autowired
    RecordProteinNitrogenDetectionService recordProteinNitrogenDetectionService;

    /**
     * 记录——蛋白性氮检测原始记录 项目新增
     * @param recordProteinNitrogenDetection 新数据
     * @return 返回对应code 0为成功
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public Result addRecordProteinNitrogenDetection(@RequestBody RecordProteinNitrogenDetection recordProteinNitrogenDetection){
        recordProteinNitrogenDetection.setId(RandomIdUtil.createRandomId());
        recordProteinNitrogenDetectionService.save(recordProteinNitrogenDetection);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, recordProteinNitrogenDetection);
    }

    /**
     * 记录——蛋白性氮检测原始记录 项目查询（三个查询项+分页）
     * @param recordMonth 记录年月（record_date）
     * @param reviewUser 审核人（review_user_name）
     * @param status 状态（status）
     * @param current 分页查询 当前页数
     * @param size 分页查询 每页最大数据量
     * @return 返回符合上述查询条件的所有数据
     */
    @ApiOperation("查看(分页)")
    @GetMapping("/pageList")
    public Result pageListRecordProteinNitrogenDetection(@RequestParam("recordMonth") String recordMonth, @RequestParam("reviewUser") String reviewUser, @RequestParam("status") String status,
                                                     @RequestParam("current") Integer current, @RequestParam("size") Integer size){
        IPage<RecordProteinNitrogenDetection> page = recordProteinNitrogenDetectionService.selectRecordProteinNitrogenDetection(recordMonth,reviewUser,status,current,size);
        return ResultUtil.success(ResultCodeEnum.SUCCESS,page);
    }

    /**
     * 记录——在线仪表药剂领用登记表 项目查询
     * @param recordMonth 记录年月
     * @param reviewUser 审核人姓名
     * @return 返回相应数据
     */
    @ApiOperation("查看导出列表")
    @GetMapping("/list")
    public Result listRecordProteinNitrogenDetection(@RequestParam("recordMonth") String recordMonth, @RequestParam("reviewUser") String reviewUser){
        List<RecordProteinNitrogenDetection> list = recordProteinNitrogenDetectionService.listRecordProteinNitrogenDetection(recordMonth, reviewUser);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, list);
    }

    /**
     * 记录——蛋白性氮检测原始记录 项目删除
     * @param id 需要删除的项目id
     * @return 返回对应code 0为成功
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Result deleteRecordProteinNitrogenDetection(@RequestParam("id") Long id){
        recordProteinNitrogenDetectionService.removeById(id);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——蛋白性氮检测原始记录 项目更新
     * @param recordProteinNitrogenDetection 新项目
     * @return 返回对应code 0为成功
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public Result updateRecordProteinNitrogenDetection(@RequestBody RecordProteinNitrogenDetection recordProteinNitrogenDetection){
        recordProteinNitrogenDetectionService.updateById(recordProteinNitrogenDetection);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——蛋白性氮检测原始记录 基础表数据查询
     * @param name form表name
     * @return 返回符合的数据
     */
    @ApiOperation("基础表数据查询")
    @GetMapping("/basicList")
    public Result listBasicProteinNitrogenDetection( @RequestParam("name") String name ){
        Map<String,Object> map = recordProteinNitrogenDetectionService.selectBasicProteinNitrogenDetection( name );
        return ResultUtil.success(ResultCodeEnum.SUCCESS, map);
    }

    /**
     * 记录——蛋白性氮检测原始记录 数据表导出
     * @param recordProteinNitrogenDetectionList 需要导出的数据列表
     * @return 返回相应数据
     * @throws IOException 异常
     */
    @ApiOperation("列表导出")
    @PostMapping(value = "/download-word")
    public Result downloadWordRecordProteinNitrogenDetection(@RequestBody List<RecordProteinNitrogenDetection> recordProteinNitrogenDetectionList, @RequestParam("recordMonth") String recordMonth,
                                                             @RequestParam("reviewUser") String reviewUser) throws IOException  {
        recordProteinNitrogenDetectionService.downloadRecordProteinNitrogenDetection(recordProteinNitrogenDetectionList, recordMonth, reviewUser);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }


}

